package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StatisVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisRedisService;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;

public class RedisDataPersistenceJob {

    @Reference
    private IStrategyStatisRedisService strategyStatisRedisService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Scheduled(cron = "0/5 * * * * ?")
    public void doWork(){
        System.out.println("-----------------vo数据持久化---start----------------");
        // 1.查询所有vo对象
        List<StrategyStatisVO> list = strategyStatisRedisService.queryStrategyStatisVoList();

        for (StrategyStatisVO vo : list) {
            // 2.将vo对象中变动的统计数据, 持久化到mysql中
            StatisVO v = new StatisVO();
            BeanUtils.copyProperties(vo, v);
            strategyDetailService.updateStategyStatis(v);

        }
        System.out.println("-----------------vo数据持久化---end----------------");


    }
}
